using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;

namespace BardsTaleViewer {
  public class AnimFrame_PC_Bard4 : IAnimFrame {
    public int _frameIndex;
    public int _animIndex;

    public int _delay;
    public byte [] _xor;
    public Bitmap _bitmapDiff;

    public int _pictureIndex2;

    public AnimFrame_PC_Bard4 (int animIndex, int frameIndex, int delay, byte [] xor, int pictureIndex2) {
      _animIndex = animIndex;
      _frameIndex = frameIndex;
      _delay = delay;
      _xor = xor;

      _pictureIndex2 = pictureIndex2;
    }

    public void CreateBitmap (Color [] colors, byte [] data) {
      byte [] mask = new byte [112 * 88 / 8];
      mask.Init (0xFF);
      for (int i = 0; i < data.Length; i++) {
        //if (_xor [i] != 0)
        //  Console.WriteLine ();
        data [i] ^= _xor [i];
        byte maskByte = (byte) (((_xor [i] != 0) ? 1 : 0) << (7 - (i % 8)));
        mask [i / 8] &= (byte) (maskByte ^ 0xFF);
      }
      //_bitmapDiff = SpriteReader.CreateBitmap (data, 0, 112, 88, 4, SpriteReader.ModesEnum.Interleaved, 2, palette, 0, SpriteReader.MasksEnum.Opaque);
      _bitmapDiff = Picture_PC.CreateBitmap (data, colors);
      _bitmapDiff.ApplyMask (mask);
      //_bitmapDiff.Save (string.Format ("bard4 PC pics DIFF {0} {1}.png", _animIndex.ToString ().PadLeft (2, '0'), _frameIndex.ToString ().PadLeft (2, '0')), ImageFormat.Png);
    }

    public static void ApplyXor () {
    }

    public Bitmap BitmapDiff {
      get {
        return (_bitmapDiff);
      }
    }

    public int Delay {
      get {
        return (_delay);
      }
    }

    public int AnimIndex {
      get {
        return (_animIndex);
      }
    }
  }
}
